<?php
class fakturproductpenjualan_model extends CI_Model{
	private $nofaktur;
	private $datefaktur;
	private $totalquantity;
	private $totalamount;
	private $typebayar;
	private $bankname;
	private $keterangan;
	private $createdBy;
	private $createdOn;
	private $lastUpdateBy;
	private $lastUpdateOn;
	private $active;

	function setNoFaktur($nfak){
		$this->nofaktur = $nfak;
	}
	function getNoFaktur(){
		return $this->nofaktur;
	}

	function setDateFaktur($dFaktur){
		$this->datefaktur = $dFaktur;
	}
	function getDateFaktur(){
		return $this->datefaktur;
	}

	function setTotalQuantity($tQuantity){
		$this->totalquantity = $tQuantity;
	}
	function getTotalQuantity(){
		return $this->totalquantity;
	}

	function setTotalAmount($tamount){
		$this->TotalAmount = $tamount;
	}
	function getTotalAmount(){
		return $this->TotalAmount;
	}

	function setTypeBayar($tBayar){
		$this->typebayar = $tBayar;
	}
	function getTypeBayar(){
		return $this->typebayar;
	}

	function setBankName($bName){
		$this->bankname = $bName;
	}
	function getBankName(){
		return $this->bankname;
	}

	function setKeterangan($ket){
		$this->keterangan = $ket;
	}
	function getKeterangan(){
		return $this->keterangan;
	}
	
	function setCreatedBy($c_by){
		$this->createdby = $c_by;
	}

	function getCreatedBy(){
		return $this->createdby;
	}

	function setCreatedOn(){
		$dateNow = date('Y-m-d H:i:s');
		$this->createdon = $dateNow;
	}

	function getCreatedOn(){
		return $this->createdon;
	}

	function setLastUpdateBy($u_by){
		$this->lastupdateby = $u_by;
	}

	function getLastUpdateBy(){
		return $this->lastupdateby;
	}

	function setLastUpdateOn(){
		$dateNow = date('Y-m-d H:i:s');
		$this->lastupdateon = $dateNow;
	}

	function getLastUpdateOn(){
		return $this->lastupdateon;
	}

	function setActive($active_val){
		$this->active = $active_val;
	}

	function getActive(){
		return $this->active;
	}

	// Call the module constructor
	function __construct(){
		parent::__construct();
	}

	function insert(){
		$data = array(
			'nofaktur' => $this->getNoFaktur(),
			'datefaktur' => $this->getDateFaktur(),
			'totalquantity' => $this->getTotalQuantity(),
			'totalamount' => $this->getTotalAmount(),
			'typebayar' => $this->getTypeBayar(),
			'bankname' => $this->getBankName(),
			'keterangan' => $this->getKeterangan(),
			'createdby' => $this->getCreatedBy(),
			'createdon' => $this->getCreatedOn(),
			'lastupdateby' => 'null',
			'lastupdateon' => 'null',
			'active' => $this->getActive()
		);
		$this->db->insert('faktur_product_penjualan',$data);
	}

	function getlistnofakturlike(){
		$this->db->select("subfaktur_product_penjualan.NoSubFaktur,faktur_product_penjualan.NoFaktur,kwitansipenjualan.NoKwitansi,
		faktur_product_penjualan.DateFaktur,kwitansipenjualan.namapelanggan,transaction_faktur_product_penjualan.HargaBarang,
		transaction_faktur_product_penjualan.quantity,transaction_faktur_product_penjualan.discount,
		transaction_faktur_product_penjualan.amount,subfaktur_product_penjualan.Keterangan,
		detail_product.KodeDetailBarang,detail_product.Productname")
        ->join('subfaktur_product_penjualan', 'faktur_product_penjualan.NoFaktur=subfaktur_product_penjualan.NoFaktur')
		->join('transaction_faktur_product_penjualan', 'transaction_faktur_product_penjualan.NoFaktur=faktur_product_penjualan.NoFaktur')
		->join('kwitansipenjualan', 'kwitansipenjualan.NoFaktur=faktur_product_penjualan.NoFaktur')
		->join('detail_product', 'detail_product.KodeDetailBarang=transaction_faktur_product_penjualan.KodeBarang')
		->where(array('subfaktur_product_penjualan.Status'=>'LUNAS','faktur_product_penjualan.Active'=>'1'))->like(array('faktur_product_penjualan.NoFaktur' => $this->getNoFaktur()))
		->group_by(array('faktur_product_penjualan.NoFaktur','transaction_faktur_product_penjualan.KodeBarang'));
        $query = $this->db->get('faktur_product_penjualan');
        return $query->result();
	}
	
	function getlistnofaktur(){
		$this->db->select("subfaktur_product_penjualan.NoSubFaktur,faktur_product_penjualan.NoFaktur,kwitansipenjualan.NoKwitansi,
		faktur_product_penjualan.DateFaktur,kwitansipenjualan.namapelanggan,transaction_faktur_product_penjualan.HargaBarang,
		transaction_faktur_product_penjualan.quantity,
		transaction_faktur_product_penjualan.discount,transaction_faktur_product_penjualan.amount,
		subfaktur_product_penjualan.Keterangan,detail_product.KodeDetailBarang,detail_product.Productname,stock.KodeSupplier")
        ->join('subfaktur_product_penjualan', 'faktur_product_penjualan.NoFaktur=subfaktur_product_penjualan.NoFaktur')
		->join('transaction_faktur_product_penjualan', 'transaction_faktur_product_penjualan.NoFaktur=faktur_product_penjualan.NoFaktur')
		->join('kwitansipenjualan', 'kwitansipenjualan.NoFaktur=faktur_product_penjualan.NoFaktur')
		->join('detail_product', 'detail_product.KodeDetailBarang=transaction_faktur_product_penjualan.KodeBarang')
		->join('stock','detail_product.KodeDetailBarang = stock.KodeDetailBarang')
		->where(array('subfaktur_product_penjualan.Status'=>'LUNAS','faktur_product_penjualan.Active'=>'1'))
		->group_by(array('faktur_product_penjualan.NoFaktur','transaction_faktur_product_penjualan.KodeBarang'));
        $query = $this->db->get('faktur_product_penjualan');
        return $query->result();
	}
	
	function deleteFakturProductPenjualan(){
		$query = $this->db->query("update faktur_product_penjualan set active='0' where nofaktur = ?",array($this->getNoFaktur()));
		return true;
	}
}